<template>
	<view>
		<custom-nav :title="'搜索'"></custom-nav>
		<view class="bgf pt20">
			<serachButton
				:showSerach="false"
				:placeholder="'搜索'"
				@serachInput="serachInput"
			></serachButton>
			<view>
				<view v-if="!serachVal" class="c6 tc mt100"
					>请输入关键词搜索</view
				>
				<view v-else>
					<view
						v-if="myCommonFunction && myCommonFunction.length > 0"
					>
						<view
							v-for="item in myCommonFunction"
							:key="item.id"
							class="flex-between p20"
						>
							<view class="df ac">
								<image
									style="width: 80rpx; height: 80rpx"
									:src="item.picUrl"
								></image>
								<text class="ml20">{{ item.name }}</text>
							</view>
							<view class="default-button" @tap="openItem(item)"
								>打开</view
							>
						</view>
					</view>
					<view v-else>
						<diy-empty></diy-empty>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
import serachButton from '@/components/serach-button/serach-button.vue'
export default {
	components: { serachButton },
	data() {
		return {
			serachVal: '',
			myCommonFunction: [],
		}
	},
	methods: {
		serachInput(val) {
			this.serachVal = val
			this.getMyCommonFunction(2, val)
		},
		accTimesByUserId(id) {
			this.$request.request(
				'workstand-platform/moduleDetail/accTimesByUserId',
				{
					data: { id },
					method: 'post',
				}
			)
		},
		openItem(row) {
			this.accTimesByUserId(row.id)
			if (row.name === '学习') {
				wx.navigateToMiniProgram({
					appId: 'wx1591cdcc0b14eb41',
					path: '/pages/index/index',
				})
			} else {
				uni.navigateTo({
					url: row.jumpUrl,
				})
			}
		},
		getMyCommonFunction(moduleId, name = '') {
			this.$request
				.request('workstand-platform/moduleDetail/getIndexIcon', {
					data: { moduleId, name },
				})
				.then((res) => {
					if (res) {
						this.myCommonFunction = res.data
					}
				})
		},
	},
}
</script>
<style lang="scss" scoped>
.default-button {
	padding: 0 20rpx;
}
</style>
